<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
<title>教师资料修改-云校通</title>
<jsp:include page="/WEB-INF/page/common/_header.jsp"></jsp:include>
<script src="<%=basePath %>/js/picker.js"></script>
<script src="<%=basePath %>/js/select.js"></script>
</head>
<body ontouchstart>
	<div class="weui_tab tab-bottom">
		<div class="weui_tab_bd">
			<div class="weui-header bg-blue"> 
		  		<div class="weui-header-left"> <a onclick="back()" href="javascript:" class="icon icon-109 f-white">返回</a> </div>
		    	<h1 class="weui-header-title">教师信息变更</h1>
		    </div>
	        <div class="weui_cells" style="margin-top: 0;">
	            <div class="weui_cell">
	                <div class="weui_cell_hd" style="position: relative;margin-right: 15px;">
	                    <input type="hidden" id="id" name="id" value="${teacher.id }"/>
	                    <c:choose>
	                    	<c:when test="${teacher.headImgUrl == null }">
	                    		<img class="circle bg-blue-b" src="<%=basePath %>/images/default.jpg" style="width: 50px;display: block"/>
	                    	</c:when>
	                    	<c:otherwise>
	                    		<img class="circle bg-blue-b" src="${config.imgUrl }${teacher.headImgUrl}" style="width: 50px;display: block"/>
	                    	</c:otherwise>
	                    </c:choose>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input" name="name" id="name" value="${teacher.name }"></p>
	                </div>
	            	<div class="weui_cell_ft" id="teacherSubmit"><a href="javascript:void(0);"class="weui_btn weui_btn_mini weui_btn_primary bg-blue">保存</a></div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">任教学科</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input" name="subjectId" id="subjectId" value="${teacher.subjectText }" data-values="${teacher.subjectId }"/></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                	<label class="weui_label">年级</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input gradeSelect" name="grade" id="grade" value="${teacher.gradeText }" data-values="${teacher.grade }"/></p>
	                </div>
	            </div>
	            
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                	<label class="weui_label">联系方式</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input" name="mobile" id="mobile" value="${teacher.mobile }" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">身份证号</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="text" class="weui_input" name="idNo" id="idNo" value="${teacher.idNo }" /></p>
	                </div>
	            </div>
	            <div class="weui_cell">
	                <div class="weui_cell_hd">
	                		<label class="weui_label">登录密码</label>
	                </div>
	                <div class="weui_cell_bd weui_cell_primary">
	                    <p><input type="password" class="weui_input" name=password id="password" value="${teacher.password }" /></p>
	                </div>
	            </div>
	        </div>
		</div>
	</div>
<jsp:include page="/WEB-INF/page/common/_footer.jsp"></jsp:include>
<script type="text/javascript">
	$(function() {
		initGradeList();
		initSubjectList();
		$("#teacherSubmit").click(function() {
			var name = $("#name").val();
			var subjectId = $("#subjectId").attr("data-values");
			var grade = $("#grade").attr("data-values");
			var mobile = $("#mobile").val();
			var idNo = $("#idNo").val();
			var password = $("#password").val();
			if(!checkName(name)) {
				$.toast("姓名格式不正确", "forbidden");
				return;
			}
			if(!checkPhone(mobile)) {
				$.toast("手机号码格式不正确", "forbidden");
				return;
			}
			if(!checkIdNo(idNo)) {
				$.toast("身份证格式不正确", "forbidden");
				return;
			}
			if(password.trim().length == 0) {
				$.toast("密码不能为空", "forbidden");
				return;
			}
			$.ajax({
		 		url : basePath + "/ls/teacher/manage/info/update",
		 		type : "post",
		 		dataType : "json",
		 		data: {
		 			id: $("#id").val(),
		 			subjectId: subjectId,
		 			grade: grade,
		 			mobile: mobile,
		 			idNo: idNo,
		 			password: password
		 		},
		 		async : false,
		 		success : function(data) {
		 			if(data.code == '000') {
		 				$.toast("修改成功");
		 				return;
		 			}
		 			$.toast(data.msg, "cancel");
		 		}, error:function(){
		 			alert("修改异常");
	      		}
	        });
		})
	});
	function initGradeList() {
		$.ajax({
	 		url : basePath + "/gradeList",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			var arr = [];
	 			for(var i in data){
	 		        if (data.hasOwnProperty(i)) {
	 		           arr.push({title: data[i], value: i})
	 		        };
	 		    }
	 			$("#grade").select({
	 		        title: "选择年级",
	 		        items: arr,
	 		        onChange: function(d) {
	 		        	this.dialog.remove();
	 		        }
	 		    });
	 		}, error:function(){
	 			alert("删除照片异常");
      		}
        });
	}
	function initSubjectList() {
		$.ajax({
	 		url : basePath + "/subjectList",
	 		type : "post",
	 		dataType : "json",
	 		async : false,
	 		success : function(data) {
	 			var arr = [];
	 			for(var i in data){
	 		        if (data.hasOwnProperty(i)) {
	 		           arr.push({title: data[i], value: i})
	 		        };
	 		    }
	 			$("#subjectId").select({
	 		        title: "选择学科",
	 		        items: arr,
	 		        onChange: function(d) {
	 		        	this.dialog.remove();
	 		        }
	 		    });
	 		}, error:function(){
	 			
      		}
        });
	}
</script>
</body>
</html>